package com.eyas.im.protocol.decoder;

import com.eyas.im.protocol.protocol.IMIdentifierProtocol;

import java.io.UnsupportedEncodingException;

/**
 * 通信端身份信息协议解析器
 */
public class IMIdentifierDecoder implements Decoder<IMIdentifierProtocol> {
    @Override
    public IMIdentifierProtocol decode(byte[] bytes) throws UnsupportedEncodingException {
        int ch1 = bytes[0];
        int ch2 = bytes[1];
        int ch3 = bytes[2];
        int ch4 = bytes[3];
        if ((ch1 | ch2 | ch3 | ch4) < 0)
            throw new UnsupportedEncodingException();
        int userid = ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4));
        return new IMIdentifierProtocol(userid);
    }
}
